# Contributor: rubicon <rubicon@mailo.com>
# Maintainer:
pkgname=ocaml-bigarray-compat
_pkgname=bigarray-compat
pkgver=1.1.0
pkgrel=1
pkgdesc="Compatibility library to use Stdlib.Bigarray when possible"
url="https://github.com/mirage/bigarray-compat"
arch="all !riscv64"  # limited by ocaml aport
license="ISC"
depends="ocaml-runtime"
depends_dev="$pkgname=$pkgver-r$pkgrel"
options="!check"
makedepends="dune ocaml ocaml-findlib ocamlbuild ocaml-compiler-libs"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/mirage/bigarray-compat/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build @install
}

check() {
	dune runtest
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml

	# There's just a readme and changelog.
	rm -Rf "$pkgdir"/usr/doc

	# FIXME: quick fix for ocaml-ctypes
	ln -sv bigarray-compat/bigarray_compat.cmi \
		"$pkgdir"/usr/lib/ocaml/
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; for path in $(find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done
}

sha512sums="
bbd9c2b319930db832ae8d41844ef81e74ced9f745f32981f2efcc9777220d55e1e5d6dc2965e9e1a6ed5e0d56ad27c672289f8dc28fbe2658f3230cbda5a800  ocaml-bigarray-compat-1.1.0.tar.gz
"
